<template>
  <el-dialog 
    class="edit-dialog"
    :visible.sync="isVisible"
    :close-on-click-modal="false"
    title="修改管理人员信息"
    width="600px">
    <el-form
      ref="editForm"
      :model="editForm"
      :rules="rules"
      autocomplete="off"
      label-position="right" 
      label-width="100px"
    >
      <el-form-item prop="input1" label="管理员姓名">
        <el-input
          ref="input1"
          v-model="editForm.input1"
          placeholder="请输入管理员姓名"
          name="input1"
          type="text"
        />
      </el-form-item>
      <el-form-item prop="input2" label="身份证号">
        <el-input
          ref="input2"
          v-model="editForm.input2"
          placeholder="请输入身份证号"
          name="input2"
          type="text"
        />
      </el-form-item>
      <el-form-item prop="input3" label="手机号码">
        <el-input
          ref="input3"
          v-model="editForm.input3"
          placeholder="请输入手机号码"
          name="input3"
          type="text"
        />
      </el-form-item>
      <el-form-item prop="input4" label="所属角色">
        <el-select v-model="editForm.input4" placeholder="请选择角色" width="100%">
          <el-option
            v-for="item in roles"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="medium" @click="isVisible=false">取 消</el-button>
      <el-button size="medium" type="primary" :loading="submitLoading" @click="editSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'ManagerEdit',
  props: {
    // 弹窗显示
    dialogVisible: { type: Boolean, default: false},
    // 弹窗类型
    type: { type: String, default: "add" }
  },
  computed: {
    // 控制显示
    isVisible: {
      get() { 
        return this.dialogVisible; 
      },
      set() {
        this.$emit('close')
        this.$refs.editForm.resetFields();
        this.editForm = this.initEditObj()
      }
    },
  },
  data() {
    return {
      submitLoading:false,
      editForm: this.initEditObj(),
      rules: {
        input1: {
          required: true,
          message: '请输入管理员姓名',
          trigger: "blur"
        },
        input2: {
          required: true,
          message: '请输入身份证号',
          trigger: "blur"
        },
        input3: {
          required: true,
          message: '请输入手机号',
          trigger: "blur"
        },
        input4: {
          required: true,
          message: '请选择角色',
          trigger: "blur"
        },
      },
      roles: [{
        value: 'admin',
        label: '超级管理员'
      }, {
        value: 'common',
        label: '普通角色'
      }],
    }
  },
  methods: {
    // 修改传递值
    setEditObj(val) {
      console.log(val);
      this.editForm = {...val};
    },
    // 重置值
    initEditObj(){
      return {
        input1: "",
        input2: "",
        input3: "",
        input4: "",
      }
    },
    editSubmit(){
       this.$refs.editForm.validate(valid => {
        if (valid) {
          this.edit();
        } else {
          return false;
        }
      });
    },
    edit(){
      this.submitLoading = true;
      // const requestData = this.editForm
      // this.submitLoading = true;
      // this.$postJson(insertDictionary, requestData).then(res => {
      //   this.submitLoading = false;
      //   if(res){
      //     this.isVisible = false;
      //     this.$emit('success')
      //   }
      // })
    }
  }
}
</script>

<style lang="scss">
.edit-dialog{
  .el-dialog__header{
    padding: 15px 20px 15px;
    .el-dialog__title{
      color: #fff;
    }

    i{
      color: #fff;
    }
    
    background-color: #006ACC;
  }

  .el-dialog__footer{
    padding: 15px 20px 15px;
    border-top: 1px solid #dfe4ea;
  }
}

</style>